package aircraft;

import java.awt.image.BufferedImage;

/**
 * 英雄机
 */
public class Hero extends FlyingObject {
    private int life;
    private int fire;

    public Hero() {
        super(97, 139, 140, 400);
        life = 5;
        fire = 0;
    }

    public void step() {
    }

    public void stepTo(int x, int y) {
        this.x = x - width / 2;
        this.y = y - height / 2;
    }

    int index = 0;

    @Override
    public BufferedImage getImage() {
        return Images.heros[index++ % Images.heros.length];
    }

    public Bullet[] shoot() {
        int xStep = width / 4;
        int yStep = 20;
        if (fire > 0) {
            Bullet[] bs = new Bullet[2];
            bs[0] = new Bullet(x + 1 * xStep, y - yStep);
            bs[1] = new Bullet(x + 3 * xStep, y - yStep);
            fire -= 2;
            return bs;
        } else {
            Bullet[] bs = new Bullet[1];
            bs[0] = new Bullet(x + 2 * xStep, y - yStep);
            return bs;
        }
    }

    public void addLife() {
        life++;
    }

    public int getLife() {
        return life;
    }

    public void subtractLife() {
        life--;
    }

    public void addFire() {
        fire += 20;
    }

    public void clearFire() {
        fire = 0;
    }

}
